import { ref, Ref, PropType, onMounted, onUnmounted } from 'vue'
const userClickOutSide = (elementRef:Ref<null | HTMLElement>) => {
  const isClickOutSide = ref(false)
  const hanlerClick = (e: MouseEvent) => {
    if (elementRef.value) {
      if (elementRef.value.contains(e.target as HTMLElement)) {
        isClickOutSide.value = false
      } else {
        isClickOutSide.value = true
      }
    }
  }
  onMounted(() => {
    document.addEventListener('click', hanlerClick)
  })
  onUnmounted(() => {
    document.removeEventListener('click', hanlerClick)
  })
  return isClickOutSide
}
export default userClickOutSide
